package io.cici.cc.mybatis.lite.executor.resultset;

import io.cici.cc.mybatis.lite.session.Configuration;
import io.cici.cc.mybatis.lite.type.TypeHandler;
import lombok.Getter;
import lombok.Setter;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Setter
@Getter
public class ResultSetWrapper {

    private final List<String> columnNames = new ArrayList<>();
    private final List<String> classNames = new ArrayList<>();
    private ResultSet resultSet;
    private Configuration configuration;

    public ResultSetWrapper(ResultSet resultSet) {
        this.resultSet = resultSet;
    }

    public ResultSetWrapper(ResultSet resultSet, Configuration configuration) throws SQLException {
        final ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
        final int columnCount = resultSetMetaData.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            columnNames.add(configuration.isUseColumnLabel() ? resultSetMetaData.getColumnLabel(i) : resultSetMetaData.getColumnName(i));

            classNames.add(resultSetMetaData.getColumnClassName(i));
        }
    }


    public TypeHandler<?> getTypeHandler(Class<?> propertyType, String columnName) {
        TypeHandler<?> handler = null;

        return handler;
    }


}
